package com.xu.sms.adapter;

import java.util.List;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xu.sms.R;
import com.xu.sms.controller.SearchActivity;
import com.xu.sms.entity.SHistory;
import com.xu.sms.utils.LogUtil;

public class SHistoryAdapter extends BaseAdapter {
	
	private List<SHistory> shList;
	private Context context;
	private Handler handler;
	private String TAG = SHistoryAdapter.class.getSimpleName();
	
	public SHistoryAdapter(List<SHistory> shList, Context context, Handler handler) {
		this.shList = shList;
		this.context = context;
		this.handler = handler;
	}

	@Override
	public int getCount() {
	
		return shList.size();
	}

	@Override
	public Object getItem(int position) {
		return shList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		if(convertView !=null){
			view = convertView;
		}else{
			view  = View.inflate(context, R.layout.listview_item_histroy, null);
		}
		ImageView item_history_iv_del = (ImageView) view.findViewById(R.id.item_history_iv_del);
		TextView item_history_tv_keyword = (TextView) view.findViewById(R.id.item_history_tv_keyword);
		final SHistory sh = shList.get(position);
		item_history_tv_keyword.setText(sh.getKeyword());
		item_history_iv_del.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
LogUtil.v(TAG, 63, "我被点击了");				
				Message msg  = Message.obtain();
				msg.what = SearchActivity.delActionCode;
				msg.obj = sh.get_id();
				handler.sendMessage(msg);
			}
		});
		return view;
	}

}
